//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    imgUrl: baseJs.imgUrl,
    pageIndex: 1,
    listData: [],
    state: '',
    // 
    heHuoRenId: "2345",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
    })
    this.AgentBigExperienceGetHeHuoRenGoodsApplyList();
  },

  

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.AgentBigExperienceGetHeHuoRenGoodsApplyList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  // 
  AgentBigExperienceGetHeHuoRenGoodsApplyList: function() {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var heHuoRenId = this.data.heHuoRenId;
    var listData = this.data.listData;
    if (pageIndex == 1) {
      wx.showLoading({
        title: '加载中',
      })
    }
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=AgentBigExperienceGetHeHuoRenGoodsApplyList&HeHuoRenId=" + heHuoRenId + "&PageSize=10&PageIndex=" + pageIndex),
      success: function(res) {
        console.log(JSON.parse(baseJs.decryUrl(res.data)));
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          json[i].ApplyMa = parseFloat(json[i].ApplyMa).toFixed(2);
          json[i].active = false;
          listData.push(json[i])
        }
        that.setData({
          listData: listData,
        })
        console.log(listData);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();
      }
    })
  },
  // 点击处理
  dealTap: function(e) {
    var that = this;
    var listData = this.data.listData;
    for (var i = 0; i < listData.length; i++) {
      listData[i].active = false;
    }
    listData[e.currentTarget.dataset.index].active = true;
    this.setData({
      listData: listData,
      smallId: e.currentTarget.dataset.smallid,
    })
  },
})